<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="用印流水号" prop="sealId">
        <el-input
          v-model="queryParams.sealId"
          placeholder="请输入用印流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="sealTitle">
        <el-input
          v-model="queryParams.sealTitle"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科室意见" prop="deptIdea">
        <el-select v-model="queryParams.deptIdea" placeholder="请选择科室意见">
          <el-option
            v-for="item in deptIdeaOptions"
            :key="item.id"
            :label="item.label"
            :value="item.value"
            @keyup.enter.native="handleQuery"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['seal:seal:export']"
            >导出
            </el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
    -->

    <el-table border fit v-loading="loading" :data="sealList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="45" align="center"/>
      <el-table-column label="用印流水号" width="145" align="center" prop="sealId"/>
      <el-table-column label="申请人姓名" width="105" align="center" prop="userName"/>
      <el-table-column label="标题" width="150" align="center" prop="sealTitle"/>
      <el-table-column label="申请人部门" width="150" align="center" prop="userDept"/>
      <el-table-column label="申请印章类别" align="center" prop="sealType">
        <template slot-scope="scope">
          <el-tag style="margin:2px" type="success" v-for="(item,index) in scope.row.sealType.split(',')" :key="index">
            {{ item }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="申请日期" align="center" prop="createTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" width="180" align="center" prop="submitTime"/>
      <el-table-column label="最后修改时间" width="180" align="center" prop="lastUpdateTime"/>
      <el-table-column
        label="科室意见"
        align="center"
        prop="deptIdea"
        width="115"
      >
        <template slot-scope="{row}">
          <el-tag
            type="info"
            v-show="row.deptIdea==='0'"
          >
            未审批
          </el-tag>
          <el-tag
            type="success"
            v-show="row.deptIdea==='1'"
          > 同意
          </el-tag>
          <el-tag
            type="danger"
            v-show="row.deptIdea==='2'"
          > 不同意
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="科室审批时间" width="180" align="center" prop="deptMasterTime"/>
      <el-table-column
        label="用印审批人意见"
        align="center"
        prop="sealIdea"
        width="115"
      >
        <template slot-scope="{row}">
          <el-tag
            type="info"
            v-show="row.sealIdea==='0'"
          >
            未审批
          </el-tag>
          <el-tag
            type="success"
            v-show="row.sealIdea==='1'"
          > 同意
          </el-tag>
          <el-tag
            type="danger"
            v-show="row.sealIdea==='2'"
          > 不同意
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="申请状态"
        align="center"
        prop="deleted"
        width="115"
      >
        <template slot-scope="{row}">
          <el-tag
            type="primary"
            v-show="row.deleted===0"
          >
            未审批
          </el-tag>
          <el-tag
            type="primary"
            v-show="row.deleted===1"
          > 审核中
          </el-tag>
          <el-tag
            type="primary"
            v-show="row.deleted===2"
          > 审批完成
          </el-tag>
          <el-tag
            type="primary"
            v-show="row.deleted===3"
          > 用户已取消
          </el-tag>
          <el-tag
            type="warning"
            v-show="row.deleted===4"
          > 退回修改
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            class="pan-btn green-btn"
            @click="handleView(scope.row)"
            v-hasPermi="['seal:dept:query']"
          >审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { deptListSeal } from '@/api/seal/seal'

export default {
  name: 'deptSealIdea',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用印表格数据
      sealList: [],
      // 用印类型数据
      sealTypeList: [],
      //已选择用印数据
      sealTypeValue: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        sealTitle: null,
        deptIdea: null,
        sealIdea: null,
        sealId: null
      },
      // 表单参数
      form: {},
      deptIdeaOptions: [
        {
          id: 1,
          value: '0',
          label: '未审核'
        },
        {
          id: 2,
          value: '1',
          label: '同意'
        },
        {
          id: 3,
          value: '2',
          label: '不同意'
        },
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询用印列表 */
    getList() {
      this.loading = true
      deptListSeal(this.queryParams).then(response => {
        this.sealList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        sealId: null,
        userId: null,
        userName: null,
        userDept: null,
        sealType: null,
        createTime: null,
        sentDept: null,
        sealTitle: null,
        sealFile: null,
        handledby: null,
        fileNum: null,
        deptMaster: null,
        deptIdea: null,
        deptRemarks: null,
        sealMaster: null,
        sealIdea: null,
        sealRemarks: null,
        userRemarks: null,
        deleted: null
      }
      this.resetForm('form')
      this.sealTypeValue = []
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sealId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 查看按钮跳转操作 */
    handleView(row) {
      this.$router.push({ path: '/deptSealIdea', query: { sealId: row.sealId } })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('seal/export', {
        ...this.queryParams
      }, `seal_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
